<?
layout("/inc/win_layout.html",{title:sysTitle}){
    ?>
 <div class="page-content">
      
        <div style="padding-bottom: 50px;">
			<button style="float: right; margin-bottom : 10px;" class="btn btn-sm btn-primary" onclick="saveUploadDatabase('0')">新增</button>	
				
		</div>
		<div style="height: 400px;overflow :auto;">
			<table class="table table-hover table-striped table-bordered table-advanced tablesorter mbn">
				<thead>
					<tr>
						<th width="8%">序号</th>
						<th>数据库中文名称</th>
						<th>数据库英文名称</th>
						<th width="30%">操作</th>
					</tr>
				</thead>
				<tbody id="databaseText"></tbody>
			</table>
		</div>
	</div>
<?} ?>

<script>
	function DatabaseList(){
		var index = parent.layer.getFrameIndex(window.name);
		window.parent.getDatabaseAll();
		parent.layer.msg('关闭成功');
		parent.layer.close(index);
	}
	$(function() {
		demo();
	});
	var saveUploadDatabaseId;
	function getSaveUploadDatabaseId() {
		return saveUploadDatabaseId;
	}
	function saveUploadDatabase(lid) {
		saveUploadDatabaseId = lid;
		parent.layer.open({
		 	type : 2,
		 	title : '数据库编辑',
		 	area : [ '650px', '550px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["knowledge-edit-sharding-database.html?winName="+window.name,'no'],
			yes: function(index,layer){
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
	                iframeWin.Page();
  	        },
			cancel : function(index) {
				
			}
		});
	}
	function delDatabase(databaseId) {
		if (confirm("是否确认删除！！"))
		{
			$.ajax({
				type : "post",
				url : "delDatabase.do",
				data : {
					"id" : databaseId
				},
				dataType : "json",
				success : function(data) {
					if(data[0] == 'yes'){
						layer.msg('删除成功');
						window.parent.getDatabaseAll();
						demo();
					}else if(data[0] == 'gx'){
						layer.msg('请先删除关联库');
					}else{
						layer.msg('删除失败');
					}
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}
	}
	function demo() {
		$.getJSON("getDatabaseAll.do",
		function(res) {
			//此处仅仅是为了演示变化的内容
			var str = "";
			for ( var i = 0; i <res.length; i++) {
				str += "<tr>"
						+"<td>"+ (i + 1)+ "</td>"
						+"<td> <label>"+ res[i].nameZh + "</label></td>"
						+"<td><label >"+ res[i].nameEn + "</label></td>"
						+"<td>"
						+ "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"delDatabase('"+ res[i].id+ "')\">删除</button>&nbsp;&nbsp;"
						+ "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"saveUploadDatabase('"+ res[i].id+ "')\">编辑</button>&nbsp;&nbsp;" 
						+ "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"testConnection('"+ res[i].id+ "')\">测试连接</button>" 
						+ "</td></tr>";
			}
			$("#databaseText").html(str);
		});
	};
	//测试连接
	function testConnection(databaseId){
		$.ajax({
			type : "post",
			url : "testConnection.do",
			data : {
				"id" : databaseId
			},
			dataType : "json",
			success : function(data) {
				if('yes' == data[0]){
					layer.msg('连接成功');
				}else{
					layer.msg('连接失败');	
				}
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
</script>